package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.dongdongshop.mapper.TbItemCatMapper;
import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.*;
import com.dongdongshop.service.TypeTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TypeTemplateServiceImpl implements TypeTemplateService {

    private static final Logger logger = LoggerFactory.getLogger(TypeTemplateServiceImpl.class);

    @Resource
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    @Resource
    private TbItemCatMapper tbItemCatMapper;

    @Override
    public PageInfo<TbTypeTemplate> getListTypeTemplate(Integer pageNumber, Integer pageSize,String name) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbTypeTemplate> tbTypeTemplates = tbTypeTemplateMapper.getListTypeTemplate(name);
        PageInfo<TbTypeTemplate> pageInfo = new PageInfo<>(tbTypeTemplates);
        logger.info("执行成功");
        return pageInfo;
    }

    @Override
    public int insertTypeTemplate(TbTypeTemplate tbTypeTemplate) {
        return tbTypeTemplateMapper.insertSelective(tbTypeTemplate);
    }

    @Override
    public TbTypeTemplate getTemplateById(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateTemplate(TbTypeTemplate tbTypeTemplate) {
        return tbTypeTemplateMapper.updateByPrimaryKeySelective(tbTypeTemplate);
    }

    @Override
    public int deleteTemplateBatch(Long[] ids) {
        return tbTypeTemplateMapper.deleteTemplateBatch(ids);
    }

    @Override
    public List<TbTypeTemplate> getTemplateAll() {
        return tbTypeTemplateMapper.selectByExample(new TbTypeTemplateExample());
    }

    @Override
    public TbTypeTemplate selectTemplateById(Long id) {
        TbItemCat tbItemCat = tbItemCatMapper.selectByPrimaryKey(id);
        TbTypeTemplate tbTypeTemplate = tbTypeTemplateMapper.selectByPrimaryKey(tbItemCat.getTypeId());
        logger.info("执行成功");
        return tbTypeTemplate;
    }
}
